import React, { useEffect, useState } from 'react';
import { Button, List, SearchBar, SideBar, Tabs, Toast } from 'antd-mobile';
import './App.css';
import { FundsObj } from './type';
import Group from './components/Group';
import FundCard from './components/FundCard';
import { useMount } from 'ahooks';
import { NoticeBar } from 'zarm';
import { fundsCode, formattedDate } from './constants';
import request, { corsRequest } from './request';


const useFundsArr = (fundsCodeArr: string[]) => {
  const [fundsInfoArr, setFundsInfoArr] = useState<FundsObj[]>([]);

  const getFundsInfo = async () => {
    try {
      const res = await request.get(
        `https://api.doctorxiong.club/v1/fund/detail/list?code=${fundsCodeArr}&startDate=${formattedDate}`,
      );

      if (res.data?.code === 400) {
        Toast.show({
          icon: 'fail',
          content: '每小时免费100次',
        });
        return;
      }

      setFundsInfoArr(res?.data?.data ?? []);
    } catch (e) {
      Toast.show({
        icon: 'fail',
        content: '请求总列表失败',
      });
    }
  };

  useMount(() => {
    getFundsInfo();
  });

  return {
    fundsInfoArr,
  };
};

export default useFundsArr;
